import 'package:flutter/material.dart';
import 'package:ls_work/a_elder/page/elder_care_play.dart';
import 'package:ls_work/a_elder/page/medical_list_page.dart';
import 'package:ls_work/res/resources.dart';
import './elder_evaluate_report.dart';

class ElderHealthFilePage extends StatefulWidget {

  final int? customerId;
  ElderHealthFilePage({Key? key, this.customerId});
  @override
  _ElderHealthFilePageState createState() => _ElderHealthFilePageState();
}

class _ElderHealthFilePageState extends State<ElderHealthFilePage>
    with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  PageController _pageController = PageController(initialPage: 0);
  TabController? _tabController;

  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    super.initState();
    _tabController = new TabController(vsync: this, length: 3);
  }

  @override
  void dispose() {
    _tabController?.dispose();
    _pageController.dispose();
    super.dispose();
  }

  _onPageChange(int index) {
    _tabController?.animateTo(index);
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: AppBar(
        title: Text('健康档案'),
        elevation: 0.0,
        bottom: TabBar(
          onTap: (index) {
            if (!mounted) {
              return;
            }
            _pageController.jumpToPage(index);
          },
          isScrollable: true,
          controller: _tabController,
          labelStyle: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
          indicatorSize: TabBarIndicatorSize.label,
          unselectedLabelColor: Colours.text_gray,
          unselectedLabelStyle: TextStyles.textGray14,
          labelColor: Colours.text_dark,
          indicatorColor: Colours.app_main,
          indicatorPadding: EdgeInsets.only(bottom: 5),
          tabs: <Widget>[
            Tab(
              text: '体检报告',
            ),
            Tab(
              text: '评估报告',
            ),
            // Tab(
            //   text: '整合性照顾计划',
            // ),
            // Tab(
            //   text: '医嘱信息',
            // ),
          ],
        ),
      ),
      body: PageView.builder(
        key: const Key('pageView'),
        itemCount: 2,
        onPageChanged: _onPageChange,
        controller: _pageController,
        itemBuilder: (BuildContext context, int index) {
          switch (index) {
            case 0:
              return MedicalListPage(customerId: widget.customerId,);
              break;
            case 1:
              return ElderEvaluateReportPage(customerId: widget.customerId,);
              break;
            // case 2:
            //   return ElderCarePlayPage(customerId: widget.customerId);
            //   break;
            default:
              return Container(child: Center(child: Text('暂无内容',style: TextStyles.textGray14,),),);
          }
        },
      ),
    );
  }
}
